package com.jwdf.uda.ui.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.jwdf.uda.databinding.ItemQuizMainDescImageBinding;
import com.jwdf.uda.ui.activity.PhotoActivity;
import com.jwdf.uda.ui.adapter.AbsViewHolder;
import com.jwdf.uda.ui.adapter.item.ReplyDetailItem;
import com.jwdf.uda.utils.DisplayUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by Administrator on 2016/9/20.
 */
public class ReplyDescImageViewHolder extends AbsViewHolder<ReplyDetailItem> {
    private ItemQuizMainDescImageBinding mItemBinding;

    public ReplyDescImageViewHolder(View convertView) {
        super(convertView);
        mItemBinding = DataBindingUtil.bind(convertView);
        mItemBinding.ivDescImg.setOnClickListener(this);
    }

    @Override
    protected void onBindView(final ReplyDetailItem item) {
        float ratio = (float) DisplayUtils.getDeviceWidth(convertView.getContext())
                / (float) item.imageWidth;
        ViewGroup.LayoutParams layoutParams = mItemBinding.ivDescImg.getLayoutParams();
        layoutParams.width = DisplayUtils.getDeviceWidth(convertView.getContext()) - mItemBinding.llImage.getPaddingLeft() - mItemBinding.llImage.getPaddingRight();
        layoutParams.height = (int) (item.imageHeight * ratio);
        mItemBinding.ivDescImg.setScaleType(ImageView.ScaleType.FIT_XY);
        mItemBinding.ivDescImg.setAdjustViewBounds(true);
        mItemBinding.ivDescImg.setLayoutParams(layoutParams);

        ImageLoader.getInstance().displayImage(item.answerDescImage, mItemBinding.ivDescImg);
    }

    @Override
    public void onClick(View v) {
//        final ArrayList<String> urls = new ArrayList<>();
//        urls.add(item.answerDescImage);
        PhotoActivity.start(v.getContext(), item.imageUrls, item.imageIndex);
    }
}
